<?php

    include('functions.php');
    
    $page = isset($_GET['page'])?abs(intval($_GET['page'])):1;
    $type = isset($_GET['type'])?$_GET['type']:'';
    switch($type) {
        case 'u':
            $type = 'u';
            $title = 'UGC留言板';
            break;
        case 'r':
            $type = 'r';
            $title = '战队招募留言板';
            break;
        case 'n':
            $type = 'n';
            $title = '公告';
            break;    
        default:
            $type = 'd';
            $title = 'DJ留言板';
            break;       
    }
       
    $json = curl("http://www.djmaxcn.com/community/GetList.asp?p={$page}&c={$type}");
    
    $rank = json_decode($json);
    
    if($rank->DATA->ROW === 0) exit('发生错误, 请返回!');
    
//    print_r($rank);
//    exit();

    getHead($title);
    echo '<table width="100%"><tr><th>标题</th><th>作者</th><th>日期</th></tr>';
    foreach($rank->DATA->RECORD as $recode) {
        $djname = isset($recode->DJNAME)?$recode->DJNAME:'白金会员';
        $count = '';
        if(isset($recode->DJNAME) && !empty($recode->HITCOUNT) && !empty($recode->COMMENTS))
            $count = "<span style=\"color: #666;\">({$recode->COMMENTS}/{$recode->HITCOUNT})</span>";
        $seq = is_numeric($recode->SEQ)?'':"<span style=\"color: #666;\">({$recode->SEQ})</span>";
        echo "<tr><td><a href=\"view.php?i={$recode->IDX}&c={$type}\">{$recode->TITLE}</a>{$seq}{$count}</td><td>{$djname}</td><td>{$recode->REGDATE}</td></tr>";
    }
    echo '</table>';
    
    $link = '<a href="?page={$page}&type='.$type.'">{$name}</a>  ';
    
    echo "<h4>第{$rank->DATA->PAGE}页, 每页{$rank->DATA->PAGESIZE}项</h4>";
    
    $prev = '';
    if($page>1) {
        $prev = str_replace('{$page}', $page-1, $link);
        $prev = str_replace('{$name}', '上一页', $prev);
    }
    
    $next = str_replace('{$page}', $page+1, $link);
    $next = str_replace('{$name}', '下一页', $next);
    
    echo "<p style=\"text-align: center;\">{$prev}&#160;&#160;&#160;{$next}</p>";
    
    getFoot();
